/**
 * Note: The returned array must be malloced, assume caller calls free().
 * https://leetcode.cn/problems/squares-of-a-sorted-array/submissions/
 */
int cmp(int* p1, int* p2)
{
    return *p1 - *p2;
}
int* sortedSquares(int* nums, int numsSize, int* returnSize) {
    int* arr = (int*)malloc(sizeof(int) * numsSize);
    if (arr == NULL)
    {
        perror("malloc fail");
        exit(-1);
    }
    for (int i = 0; i < numsSize; ++i)
    {
        arr[i] = nums[i] * nums[i];
    }
    *returnSize = numsSize;
    qsort(arr, numsSize, sizeof(int), cmp);

    return arr;
}